<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class ScheduleController extends Controller
{
	public function getIndex(Request $request)
	{
		$name = $request->session()->get('username');
		$sinfo = DB::table('schedule')->where('PersonName',$name)->get();
		// dd($sinfo);
		return view('Lzk.Schedule.Schedule',['sinfo'=>$sinfo]);
	}

	//解析添加
	public function getAdd(Request $request)
	{	
		return view('Lzk.Schedule.AddSchedule');
	}
	//执行添加
	public function postInsert(Request $request)
	{
		// dd($request->all());
		$ins = $request->all();
		$name = $request->session()->get('username');
		$ins['PersonName'] = $name;
		$ins['Date'] = time();
		$res = DB::table('schedule')->insert($ins);
		if($res){
			return redirect('/Lzk/Schedule');
		}else{
			return back();
		}
	}

	//删除
	public function getDel($id)
	{
		$del = DB::table('schedule')->where('id',$id)->delete($id);
		if($del){
			return redirect('/Lzk/Schedule');
		}else{
			return back();
		}
	}

	//解析查看
	public function getLook($id)
	{
		$look = DB::table('schedule')->where('id',$id)->get();
		// dd($look);
		return view('Lzk/Schedule/LookSchedule',['look'=>$look]);
	}

}
